<?php
/**
 * Generate file i18n.xml for Android StylaNavi
 */
$csv = 'i18n.csv';
$outputDir = '../android-music-clock/res';

echo "Export i18n.xml file to $outputDir\n";
$itemSets = array();

$handle = fopen($csv, 'r');

// Read the header.
$data = fgetcsv($handle);
$columnIndexes = array(); 
for ($i = 1; $i < count($data); $i++) {
  $lang = trim($data[$i]);
  $columnIndexes[$lang] = $i;
  $itemSets[$lang] = array();
}

// Read data.
while (($data = fgetcsv($handle)) !== FALSE) {
  $name = $data[0];
  foreach ($columnIndexes as $lang => $index) {
    $str = "  <string name=\"$name\">{$data[$index]}</string>";
    $itemSets[$lang][] = $str;
  }
}

fclose($handle);

// Output
foreach ($itemSets as $lang => $set) {
  $xml = join($set, "\n");
  $xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n"
      . "<resources>\n"
      . $xml . "\n"
      . '</resources>';
  $dir = $lang ? "values-$lang" : 'values';
  file_put_contents("$outputDir/$dir/i18n.xml", $xml);
}
?>
<?php
class Translation {
  public $message;
  public $translation;
  
  public function __construct($message, $translation)
  {
  }
}
?>